package org.example.service;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.example.mapper.IpfsMapper;
import org.example.pojo.Ipfs;
import org.example.util.SqlSessionFactoryUtils;

import java.util.List;

public class IpfsService {

    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();

    public List<Ipfs> query()  {


        SqlSession session = sqlSessionFactory.openSession();
        IpfsMapper mapper = session.getMapper(IpfsMapper.class);
        List<Ipfs> ipfs = mapper.query();
        session.close();
        return ipfs;
    }


    public void add(Ipfs ipfs){

        SqlSession session = sqlSessionFactory.openSession();
        IpfsMapper mapper = session.getMapper(IpfsMapper.class);
        mapper.add(ipfs);
        session.commit();
        session.close();

    }

    public void delete(String name){

        SqlSession session = sqlSessionFactory.openSession();
        IpfsMapper mapper = session.getMapper(IpfsMapper.class);
        mapper.delete(name);
        session.commit();
        session.close();
    }
}
